package com.gitee.feizns.quickstart.web.ex.impl;

import com.gitee.feizns.quickstart.domain.vo.Ret;
import com.gitee.feizns.quickstart.web.decrypt.DecryptionAlgorithm;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 解密算法解密失败处理器
 * @author feizns
 * @since 2023/3/8
 */
public class DecryptionAlgorithmDecryptionFailedExceptionHandler extends AbstractExceptionHandler<DecryptionAlgorithm.DecryptionFailedException> {

    /**
     * 默认消息
     */
    public static final String DEFAULT_MSG = "验签失败、请检查公钥.";

    /**
     * 响应的Http状态
     */
    private final HttpStatus httpStatus;

    public DecryptionAlgorithmDecryptionFailedExceptionHandler(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
    }

    @Override
    public ResponseEntity<Ret<?>> handle(DecryptionAlgorithm.DecryptionFailedException e) {
        return ResponseEntity.status(httpStatus)
                .body(Ret.error(HttpStatus.BAD_REQUEST.value(), DEFAULT_MSG));
    }

}
